package emulator.shell.GUI;

import java.awt.Color;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;

import emulator.assembler.Assembler;
import emulator.hardware.CPU;
import emulator.hardware.bus.Bus;
import emulator.hardware.io.peripherals.iec.IecSim;
import emulator.hardware.memory.MemoryBlockInterface;

public class ShellUI {
	private ConsoleFrame console;

	public ShellUI(CPU cpu, MemoryBlockInterface memory, Bus bus)
	{
		console = ConsoleFrame.createConsole(cpu, memory, bus);
		ConsoleOutputStream outf = new ConsoleOutputStream(console, Color.black, true);
		ConsoleInputFeedback feedback = new ConsoleInputFeedback(outf);
		console.addObserver(feedback);
	}
	
	public InputStream createIn() {
		ConsoleInputStream in = new ConsoleInputStream();
		console.addObserver(in);
		return in;
	}
	
	public PrintStream createOut() {
		OutputStream out = new ConsoleOutputStream(console, Color.gray, false);
		return new PrintStream(out);
	}
	
	public PrintStream createErr() {
		OutputStream err = new ConsoleOutputStream(console, Color.red, true);
		return new PrintStream(err);
	}

	/**
	 * @return
	 * @see emulator.shell.GUI.ConsoleFrame#getAssembler()
	 */
	public Assembler getAssembler() {
		return console.getAssembler();
	}

	/**
	 * @param assembler
	 * @see emulator.shell.GUI.ConsoleFrame#setAssembler(emulator.assembler.Assembler)
	 */
	public void setAssembler(Assembler assembler) {
		console.setAssembler(assembler);
	}

	public void setIecSim(IecSim iec_sim) {
		console.setIecSim(iec_sim);
	}
}
